<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    const notificationIcon = 'https://static.mengniang.org/common/d/d1/%E5%A4%A7%E8%90%8C%E5%AD%97.png'

    async function registerService() {
      if (Notification === undefined || navigator.serviceWorker === undefined) {
        return alert('当前浏览器不支持通知插件，请从您的用户页中移除！')
      }
      
      if(Notification.permission === 'default') {
        alert('点击确定关闭这条消息后，将弹出授予通知权限的窗口，届时请点击“允许”，以保证插件的正常运行。')
      }

      Notification.requestPermission(() => {
        const status = Notification.permission
        
        if (status === 'granted') {
          new Notification('欢迎', {
            body: '您已经成功开启实时通知功能，欢迎使用！',
            icon: notificationIcon
          })
        }

        if (status === 'denied') {
          alert('您未能正确授予通知权限，若要继续使用，请在url栏左侧点击小锁标志开启权限，若无法设置，请从你的用户页删去此插件。')
        }
      })
    }

    registerService()
  </script>
</head>
<body>
  
</body>
</html>